﻿using System.Data;
using WFC.BL.Interfaces.DomainModels;
using WFC.BL.Interfaces.Enumerations;
using WFC.DAL.Interfaces.PersistentStorage;
using WFC.DAL.Interfaces.StatementSources;
using WFC.DAL.StatementSources;

namespace WFC.DAL.PersistentStorage
{
    public class DataService : IDataService
    {

        public DataSet InsertContents(CmsPageMode cmsPageMode, string contentData, int createdBy)
        {
            IStatementSource statementSource =
                new InsertContentsStatementSource(cmsPageMode, contentData, createdBy);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet ReadContentsById(int contentId)
        {
            IStatementSource statementSource = new ReadByIdContentsStatementSource(contentId);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet UpdateContents(IContentMaintainable content)
        {
            IStatementSource statementSource = new UpdateContentsStatementSource(content);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet DeleteContents(int contentId)
        {
            IStatementSource statementSource = new DeleteContentsStatementSource(contentId);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet InsertPosts(string title, string body, string shortDescription, string tags, int createdBy)
        {
            IStatementSource statementSource = 
                new InsertPostStatementSource(title, body, shortDescription, tags, createdBy);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet ReadPostsById(int postId)
        {
            IStatementSource statementSource = new ReadByIdPostsStatementSource(postId);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet UpdatePosts(IPostable post)
        {
            IStatementSource statementSource = new UpdatePostsStatementSource(post);
            return DbManager.ExecuteStatement(statementSource);
        }

        public DataSet DeletePosts(int postId)
        {
            IStatementSource statementSource = new DeletePostsStatementSource(postId);
            return DbManager.ExecuteStatement(statementSource);
        }

    }
}
